import Vuex from 'vuex'
import Vue from 'vue'
// import { staticUrl } from "@/api/url";

Vue.use(Vuex)

const store = new Vuex.Store({
  state: () => {
    return {
      name: 'Main',
      tabList: [],
      userinfo: {
        ident: 0,
        name: '',
      },
      unread_num: 0,
      tabarIndex: 0,
      userPageActionType: 'admin',
      userPageActionId: 0,
      fileAction: {
        caseid: 0,
        type: 'files',
        lefttit: '',
        tit: '',
      },
    }
  },

  mutations: {
    setTabList(state, bindevice) {
      const nav_config_hasvideo = [
        {
          name: 'Main',
          text: 'Projects',
          selectedIconPath: '/static/project_s.png',
          iconPath: '/static/project.png',
        },
        {
          name: 'Monitor',
          text: 'Monitor',
          selectedIconPath: '/static/videoicon_s.png',
          iconPath: '/static/videoicon.png',
        },
        {
          name: 'Contacts',
          text: 'Contacts',
          selectedIconPath: '/static/contact_s.png',
          iconPath: '/static/contact.png',
        },
				{
          name: 'Messages',
          text: 'Messages',
          selectedIconPath: '/static/contact_s.png',
          iconPath: '/static/contact.png',
        },
        {
          name: 'Setting',
          text: 'Setting',
          selectedIconPath: '/static/set_s.png',
          iconPath: '/static/set.png',
          count: 0,
        },
      ]

      const nav_config_nohasvideo = [
        {
          name: 'Main',
          text: 'Projects',
          selectedIconPath: '/static/project_s.png',
          iconPath: '/static/project.png',
        },
        {
          name: 'Contacts',
          text: 'Contacts',
          selectedIconPath: '/static/contact_s.png',
          iconPath: '/static/contact.png',
        },
        {
          name: 'Setting',
          text: 'Setting',
          selectedIconPath: '/static/set_s.png',
          iconPath: '/static/set.png',
          count: 0,
        },
      ]
			// // 如果state的userinfo的ident为3， 设计师为2没有messages页面
			// if (state.userinfo.ident !== 1) {
			// 		nav_config_hasvideo.splice(3, 1)
			// }
      //设计师也要所有权限了
      state.tabList =
        bindevice === 1 ||state.userinfo.ident === 2 ? nav_config_hasvideo : nav_config_nohasvideo
    },
    changeFileAction(state, f) {
      if (f) {
        state.fileAction.caseid = f.caseid
        state.fileAction.type = f.type
        state.fileAction.lefttit = f.lefttit
        state.fileAction.tit = f.tit
      }
    },
    changeUserIdent(state, ident) {
      if (ident) {
        state.userinfo.ident = parseInt(ident)
      }
    },
    changeUserName(state, name) {
      if (name) {
        state.userinfo.name = name
      }
    },
    chageUserPageType(state, str) {
      if (str) {
        state.userPageActionType = str
      }
    },
    chageUserPageId(state, id) {
      if (id) {
        state.userPageActionId = id
      }
    },
    changeTabar(state, index) {
      console.log('传来的值',index)
      state.tabarIndex = index
    },
    changeUnreadNum(state, n) {
      if (n > 0) {
        state.tabList[2].count = n
      }
    },
    ChangeName(state, user) {
      if (state.userinfo) {
        state.userinfo.name = user
      }
    },
    ChangeLastTabName(state, route) {
      state.lastTabName = route
    },
  },
})

export default store
